package com.niiwoo.civet.user.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.joda.time.Days;
import org.joda.time.LocalDate;

import java.util.Arrays;
import java.util.Date;
import java.util.Optional;

/**
 * @Description: 用户资料或认证状态枚举
 * @Author:LiJian
 * @Date:2017/4/25 14:46.
 */
public class UserDataStatusEnum {


    /**
     * 个人资料
     **/
    @Getter
    @AllArgsConstructor
    public enum PersonInfoStatus {
        NOFILL((byte) 0, "未填写"),
        COMPLETE((byte) 1, "已完成"),
        TO_BE_MODIFIED((byte) 2, "待修改");
        private Byte status;
        private String desc;

        public static PersonInfoStatus of(byte value) {
            for (PersonInfoStatus t : values()) {
                if (t.status == value) {
                    return t;
                }
            }
            return null;
        }
    }

    /**
     * 身份二要素认证（实名认证）
     **/
    @Getter
    @AllArgsConstructor
    public enum RealNameAuthStatus {
        NOT_CERTIFIED((byte) 0, "未实名认证"),
        PASS_CERTIFIED((byte) 1, "通过实名认证");
        private Byte status;
        private String desc;

        public static RealNameAuthStatus of(byte value) {
            for (RealNameAuthStatus t : values()) {
                if (t.status == value) {
                    return t;
                }
            }
            return null;
        }

    }

    /**
     * OCR状态
     **/
    @Getter
    @AllArgsConstructor
    public enum OCRStatus {
        NOT_OCR((byte) 0, "未OCR"),
        YES_OCR((byte) 1, "已OCR");
        private Byte status;
        private String desc;

        public static OCRStatus of(byte value) {
            for (OCRStatus t : values()) {
                if (t.status == value) {
                    return t;
                }
            }
            return null;
        }

    }

    /**
     * 肖像认证状态
     **/
    @Getter
    @AllArgsConstructor
    public enum PortraitAuthStatus {
        NOT_CERTIFIED((byte) 0, "未认证"),
        NEED_APPROVE((byte) 1, "需要人工审核"),
        PASS_CERTIFIED((byte) 2, "认证通过"),
        NOT_PASS((byte) 3, "认证不通过"),
        REVIEW((byte) 4, "审核中");

        private Byte status;
        private String desc;

        public static PortraitAuthStatus of(byte value) {
            for (PortraitAuthStatus t : values()) {
                if (t.status == value) {
                    return t;
                }
            }
            return null;
        }

        public static boolean except(Byte value, PortraitAuthStatus... status) {
            return status != null && status.length > 0 && Arrays.asList(status).contains(of(value));
        }


    }

    /**
     * 开户
     **/
    @Getter
    @AllArgsConstructor
    public enum OpenBankAccountStatus {
        NOT_BIND((byte) 0, "未开户"),
        PASS_BIND((byte) 1, "开户成功"),
        NOT_ACTIVE((byte) 2, "未激活");
        private Byte status;
        private String desc;
        public static OpenBankAccountStatus of(byte value) {
            for (OpenBankAccountStatus t : values()) {
                if (t.status == value) {
                    return t;
                }
            }
            return null;
        }


    }


    /**
     * 芝麻授权状态
     **/
    @Getter
    @AllArgsConstructor
    public enum ZhimaCreditStatus {
        NOAPPLY((byte) 0, "未授权"),
        APPLYING((byte) 1, "授权中"),
        PASS_APPLY((byte) 2, "已授权"),
        FAIL_APPLY((byte) 3, "授权失败"),
        EXPIRED((byte) 4, "已过期");
        private Byte status;
        private String desc;
        public static ZhimaCreditStatus getByStatus(int status) {
            Optional<ZhimaCreditStatus> zhima =
                    Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return zhima.isPresent() ? zhima.get() : null;
        }
    }


    /**
     * 运营商授权状态
     **/
    @Getter
    @AllArgsConstructor
    public enum PhoneOperatorStatus {
        NOCREDIT((byte) 0, "未授权"),
        ALREADY_CREDIT((byte) 1, "已授权"),
        GETSUCCESS((byte) 2, "已验证（获取数据）"),
        GETFAIL((byte) 3, "验证失败（获取数据失败）"),
        EXPIRED((byte) 4, "已过期");
        private Byte status;
        private String desc;
        public static PhoneOperatorStatus getByStatus(int status) {
            Optional<PhoneOperatorStatus> telOperator =
                    Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return telOperator.isPresent() ? telOperator.get() : null;
        }

    }

    /** 社保授权状态 **/
    @Getter
    @AllArgsConstructor
    public enum SocialSecurityStatus {
        NOCREDIT((byte) 0, "未授权"),
        ALREADY_CREDIT((byte) 1, "已授权"),
        GETSUCCESS((byte) 2, "已验证（获取数据）"),
        GETFAIL((byte) 3, "验证失败（获取数据失败）"),
        EXPIRED((byte) 4, "已过期"),
        DIFFER((byte)5, "验证失败（获取成功但身份不一致）");
        private Byte status;
        private String desc;
        public static SocialSecurityStatus getByStatus(int status) {
            Optional<SocialSecurityStatus> socialSecurity =
                    Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return socialSecurity.isPresent() ? socialSecurity.get() : null;
        }
    }

    /**
     * 信用卡授权状态
     **/
    @Getter
    @AllArgsConstructor
    public enum CreditCardStatus {
        NOCREDIT((byte) 0, "未授权"),
        ALREADY_CREDIT((byte) 1, "已授权"),
        GETSUCCESS((byte) 2, "已验证（获取数据）"),
        GETFAIL((byte) 3, "验证失败（获取数据失败）"),
        EXPIRED((byte) 4, "已过期");
        private Byte status;
        private String desc;
        public static CreditCardStatus getByStatus(int status) {
            Optional<CreditCardStatus> telOperator =
                    Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return telOperator.isPresent() ? telOperator.get() : null;
        }

    }

    /**
     * 学历授权状态
     **/
    @Getter
    @AllArgsConstructor
    public enum EducationStatus {
        NOCREDIT((byte) 0, "未授权"),
        ALREADY_CREDIT((byte) 1, "已授权"),
        GETSUCCESS((byte) 2, "已验证（获取数据）"),
        GETFAIL((byte) 3, "验证失败（获取数据失败）"),
        EXPIRED((byte) 4, "已过期");
        private Byte status;
        private String desc;
        public static EducationStatus getByStatus(int status) {
            Optional<EducationStatus> telOperator =
                    Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return telOperator.isPresent() ? telOperator.get() : null;
        }

    }

    /**
     * 京东授权状态
     **/
    @Getter
    @AllArgsConstructor
    public enum JdStatus {
        NOCREDIT((byte) 0, "未授权"),
        ALREADY_CREDIT((byte) 1, "已授权"),
        GETSUCCESS((byte) 2, "已验证（获取数据）"),
        GETFAIL((byte) 3, "验证失败（获取数据失败）"),
        EXPIRED((byte) 4, "已过期");
        private Byte status;
        private String desc;
        public static JdStatus getByStatus(int status) {
            Optional<JdStatus> telOperator =
                    Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return telOperator.isPresent() ? telOperator.get() : null;
        }

    }
    
    /**
     * 淘宝授权状态
     **/
    @Getter
    @AllArgsConstructor
    public enum TaobaoStatus {
        NOCREDIT((byte) 0, "未授权"),
        ALREADY_CREDIT((byte) 1, "已授权"),
        GETSUCCESS((byte) 2, "已验证（获取数据）"),
        GETFAIL((byte) 3, "验证失败（获取数据失败）"),
        EXPIRED((byte) 4, "已过期");
        private Byte status;
        private String desc;
        public static TaobaoStatus getByStatus(int status) {
            Optional<TaobaoStatus> optional = Arrays.stream(values()).filter(value -> value.getStatus() == status).findFirst();
            return optional.isPresent() ? optional.get() : null;
        }

    }


    /** 法大大 **/
    @Getter
    @AllArgsConstructor
    public enum FadadaStatus {
        NOT_CERTIFIED((byte) 0,"未授权"),
        PASS_CERTIFIED((byte) 1,"已授权");
        private Byte status;
        private String desc;
    }

    /** 身份证过期状态 **/
    @Getter
    @AllArgsConstructor
    public enum IdCardExpiredStatus {
        VALID((byte) 0,"未过期"),
        EXPIRING((byte) 1,"快过期"),
        EXPIRED((byte) 2,"已过期");
        private Byte status;
        private String desc;

        public static IdCardExpiredStatus get(Date endDate, int days) {
            LocalDate now = new LocalDate();
            LocalDate end = new LocalDate(endDate);
            if (now.isBefore(end)) {
                if (Days.daysBetween(now.toDateTimeAtStartOfDay(), end.toDateTimeAtStartOfDay()).getDays() <= days) {
                    return EXPIRING;
                } else {
                    return VALID;
                }
            } else {
                return EXPIRED;
            }
        }

        public static boolean isValid(Date endDate, int days) {
            return VALID == get(endDate, days);
        }

    }

    /**
     * 手持照片上传状态
     **/
    @Getter
    @AllArgsConstructor
    public enum HandPhotoStatus {
        NO_UPLOAD((byte) 0, "未上传"),
        UPLOADED((byte) 1, "已上传");
        private Byte status;
        private String desc;
    }

    /**
     * （极速借）还款服务委托书生成状态
     **/
    @Getter
    @AllArgsConstructor
    public enum WithholdContractSignStatus {
        NO_SING((byte) 0, "未生成"),
        ALREADY_SIGN((byte) 1, "已生成"),
        FAIL_SIGN((byte) 2, "生成失败");
        private Byte status;
        private String desc;
    }

}
